package com.ruix.app.mapper;

import com.ruix.app.model.PurseRecord;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;

/**
 * Created by hadexs on 2017/4/21.
 */

public class PurseRecordMapper implements ApiMapper<ArrayList<PurseRecord>> {

    @Override
    public ArrayList<PurseRecord> transform(JSONObject response) {
        ArrayList records = new ArrayList();
        JSONObject data = response.optJSONObject("data");
        if (data != null) {
            JSONArray listArray = data.optJSONArray("list");
            if (listArray != null) {
                for (int i = 0; i < listArray.length(); i++) {
                    PurseRecord notice = new PurseRecord().parse(listArray.optJSONObject(i));
                    records.add(notice);
                }
            }

        }
        return records;
    }
}
